//操作成功之后提示
function success(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();

}
//操作失败之后提示
function fail(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();
}
function myfresh(){
	window.location.href=window.location.href;
}
//一下是商品上传的js
$("button[name='addNewSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addNewSeries","上架新系列产品");
	if($("#ulHead").find("a[href='#addNewSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}
	
});
//点击老系列上传
$("button[name='addOldSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addOldSeries","上架已有系列产品");
	if($("#ulHead").find("a[href='#addOldSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}	
	
});
//点击布艺帘
$("button[name='addBuYiLianButton']").click(function(){
	var lLable=makeUlOfHead("addGoodsDeatil","布艺帘(商品信息)上架");
	if($("#ulHead").find("a[href='#addGoodsDeatil']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
});

//点击布艺帘中的下一步
$("#buYiLianNext").click(function(){
	$.post(
			"../shoppingmall/addgoods.do",
			$("#sampleT").serialize(),
			function(data){
				alert(data);
			}
	);
	var jiegou=$("#addGoodsDeatil>form>div> div[name='jieGouDiv']>[type='radio']:checked").val();
	if(jiegou==0){
		//单布 有帘头 主布一定有, 配布不一定
		var lLable=makeUlOfHead("addLianTou","帘头选择");
		if($("#ulHead").find("a[href='#addLianTou']").length==0){
			$("#ulHead").append(lLable);
			$("#addZhuBu>div").append(makeFrom);
			var modelId=$(this).parent().attr("id");
			var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
			$('#ulHead li:eq('+index+') a').tab('show');
		}			
	}else if(jiegou==1){
		//单纱 没帘头 只有纱
		var lLable=makeUlOfHead("addSha","上传纱信息");
		if($("#ulHead").find("a[href='#addSha']").length==0){
			$("#ulHead").append(lLable);
			$("#addSha>div").append(makeFrom);
			var modelId=$(this).parent().attr("id");
			var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
			$('#ulHead li:eq('+index+') a').tab('show');
		}		
		
	}else if(jiegou==2){

		//布加纱
		var lLable=makeUlOfHead("addSha","上传纱信息");
		if($("#ulHead").find("a[href='#addSha']").length==0){
			$("#ulHead").append(lLable);
			$("#addSha>div").append(makeFrom);
			var modelId=$(this).parent().attr("id");
			var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
			$('#ulHead li:eq('+index+') a').tab('show');
		}		
		//把配布中的, 商品上传, 该成选纱
		$("#shaButtonNext").remove();
		$("#addSha").append('<a id="selectLianTou" class="btn btn-info btn-Next" onclick="selectLianTou()">帘头选择</a>');
	}
	
});
//选纱中点击选帘头

function selectLianTou(){
	var lLable=makeUlOfHead("addLianTou","帘头选择");
	if($("#ulHead").find("a[href='#addLianTou']").length==0){
		$("#ulHead").append(lLable);
		$("#addZhuBu>div").append(makeFrom);
		var modelId=$("#selectLianTou").parent().attr("id");
		console.log("我看看id=",modelId);
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
	
	
}


//纱中点击开始上传商品
$("#shaButtonNext").click(function(){
	//开始上传商品
	
	
});
//帘头中点击下一步
$("#LianTouButtonNext").click(function(){
	var lLable=makeUlOfHead("addZhuBu","上传主布信息");
	if($("#ulHead").find("a[href='#addZhuBu']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');

	}	
	
});
//主布中上传配布
$("#zhuBuButtonNext").click(function(){
	var lLable=makeUlOfHead("addPeiBu","上传配布信息");
	if($("#ulHead").find("a[href='#addPeiBu']").length==0){
		$("#ulHead").append(lLable);
		$("#addPeiBu>div").append(makeFrom);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}	
});
function addGoOnZhuBu(){
	$("#yidongde").remove();
	$("#tianjiashuxing").append(makeFrom);
	$("#tianjiashuxing").append('<div id="yidongde">'+                  							                       		                      		               
								'<a class="btn btn-info btn-Next" onclick="addGoOnZhuBu()">继续添加布料</a>'+
								'<a href="../shoppingmall/test.do" class="btn btn-info btn-Next">上传详情图片</a>'+
								'</div>');
}

$("#addGoOnPeiBu").click(function(){
	$("#addPeiBu>div").append(makeFrom);
	
});
//配布中, 点击上传商品
$("#peiBuButtonNext").click(function(){
	//开始上传商品
});
$("#addGoOnSha").click(function(){
	$("#addSha>div").append(makeFrom);
	
});



function makeUlOfHead(idName,stringName){
	var aLable='<a href="#'+idName+'" data-toggle="tab">'+stringName+'</a>';
	var lLable=$("<li class=''></li>");
	lLable.append(aLable);
	return lLable;
}

//上传主布,配布,纱,都要用js拼, 因为他可能要多个 这里写一个生成主布的方法
//这个方法生成key 和空格
function makeDivInput(inputName,lableString){
	var lab='<label>'+lableString+'</label>';
	var input='<input type="text" name="'+inputName+'" placeholder="'+lableString+'">';
	var divForm=$('<div></div>');
	divForm.append(lab);
	divForm.append(input);
	return divForm;
}
//返回主布的表格
function makeFrom(){
	var form =$('<form class="form-horizontal" role="form"></form>');
	form.append(makeDivInput("inputName","型号:"));
	form.append(makeDivInput("inputName","规格:"));
	form.append(makeDivInput("inputName","采购价:"));
	form.append(makeDivInput("inputName","供应商代号:"));
	form.append(makeDivInput("inputName","供应商:"));
	form.append(makeDivInput("inputName","花距:"));
	form.append(makeDivInput("inputName","定高:"));
	form.append(makeDivInput("inputName","定宽:"));
	form.append('<h3>倒幅:</h3>');
	form.append('<div class="innerLianTou"><input type="radio" name="swag" id="wuLianTou" checked="checked"/><label for="wuLianTou">不可倒幅</label><br /><input type="radio" name="swag" id="youLianTou" />		<label for="youLianTou">可倒幅</label>	</div>');
	form.append('<h3>拼接:</h3>');
	form.append('<div class="innerLianTou"><input type="radio" name="swag" id="wuLianTou" checked="checked"/><label for="wuLianTou">横拼</label><br /><input type="radio" name="swag" id="youLianTou" />		<label for="youLianTou">竖拼</label>	</div>');
	form.append('<hr style="border:0;background-color:#ff0000;height:1px;">');
	return form;
}
//点击继续上传图片按钮
$(".goOnUploadButton").click(function(){
	alert("-----")
	$("#goodsDeatilUpload>div").append(makeUploadDiv);
	$("#goodsDeatilUpload>div").append("<br>");
	
});
//做上传div
function makeUploadDiv(){
	var imgDiv='<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>';
	var inputDiv='<div><input type="file" class="default"></div>';
	var uploadDiv=$('<div class="fileupload fileupload-new" data-provides="fileupload"></div>');
	uploadDiv.append(imgDiv);
	uploadDiv.append(inputDiv);
	return uploadDiv;
}

//点击上传原有系列

